package cn.fyl.controller;

import cn.fyl.domain.User;
import cn.fyl.feign.UserFeignService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserFeignService userFeignService;

    @GetMapping("/getById/{id}")
    //@SentinelResource(value = "user-getById",fallback = "fallbackUser")
    public User getById(@PathVariable("id") Long id){
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return userFeignService.getById(id);
    }

    public User fallbackUser(@PathVariable("id") Long id){
        return new User(-1L,"熔断了","稍后重试");
    }
}
